package com.stylefeng.guns.rest.modular.viewrecord.service;

import com.baomidou.mybatisplus.mapper.Condition;
import com.stylefeng.guns.rest.common.persistence.dao.ShareRecordMapper;
import com.stylefeng.guns.rest.common.persistence.model.ShareRecord;
import com.stylefeng.guns.rest.modular.viewrecord.controller.dto.ShareRecordRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by ASUS-PC on 2018/6/28.
 */
@Service
public class ShareRecordService {
    @Autowired
    ShareRecordMapper shareRecordMapper;


    //插入分享记录
    public int insertRecord(ShareRecordRequest request){
        ShareRecord shareRecord = new ShareRecord();
        shareRecord.setArtitleId(request.getArtitleId());
        if(request.getUserId()>0){
            shareRecord.setUserId(request.getUserId());
        }
        shareRecord.setShareType(request.getShareType());
        shareRecord.setCreateTime(new Date());
        return shareRecordMapper.insert(shareRecord);
    }

    //获取分享数量
    public int queryVideoContentNums(int artitleId){
        return shareRecordMapper.selectList(Condition.create().eq("artitle_id",artitleId)).size();
    }

}
